package com.pkk.penguin.frame.know.boot.schedule.zhiyi.db;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pkk.penguin.frame.know.boot.config.handle.zhiyi.db.support.support.ExecPingTaiSingleSupport;
import com.pkk.penguin.frame.know.boot.config.handle.zhiyi.db.support.util.ExecUtil;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @description: 重试连接数据库配置
 * @author: peikunkun
 * @create: 2020-06-13 11:30
 **/
@Slf4j
@Component
public class RetryConnectionDb {

  /**
   * @Description: 数据库连接会话
   * @return: void
   * @Author: peikunkun
   * @Date: 2020/5/20 0020 下午 8:16
   */
  @Scheduled(cron = "0 0/5 * * * ?")
  public void keepDbConnection() {
    try {
      log.warn("[{}]-[数据库连接检测->BEGIN]", DateUtil.now());
      final ExecPingTaiSingleSupport instance = ExecPingTaiSingleSupport.getInstance();
      Set<String> support = ExecUtil.PINGTAI_KEY_INFO.keySet();
      String command = "select 1;";
      final JSONArray exec = instance.execPlus(support, command, true, null);
      log.warn("[{}]-[数据库连接检测->END]->[{}]", DateUtil.now(), JSONObject.toJSONString(exec));
    } catch (Exception e) {
      log.error("[{}]-[数据库连接检测->ERROR]->[{}]", DateUtil.now(), e.getMessage());
    }
  }

}
